<?
	$functions_uri = dirname(__FILE__) . "/drizzo/engine/functions.php";
	require_once($functions_uri);
	drizzo_startup();
	$drizzo_limit = drizzo_global_options('posts_per_page');
	$template_check = drizzo_theme('local_dir') . "index.php";
	if(file_exists($template_check)) {
		if(isset($_GET['view'])) {
			$drizzo_post_id = $_GET['view'];
		} elseif(isset($_GET['event'])) {
			$drizzo_event_id = $_GET['event'];
		} else {
			extract(drizzo_parse_the_uri());
		}

		if($drizzo_feed) {
			$include_url = dirname(__FILE__) . "/feed.xml.php";
		} elseif($drizzo_page_type == 'tags' && file_exists(drizzo_theme('local_dir') . "tags.php")) {
			$include_url = drizzo_theme('local_dir') . "tags.php";
		} elseif($drizzo_page_type == 'gallery' && file_exists(drizzo_theme('local_dir') . "gallery.php")) {
			$include_url = drizzo_theme('local_dir') . "gallery.php";
		} elseif($drizzo_post_id && !$_GET['id'] && !$drizzo_page_type) {
			$post_id_lookup = @mysql_query("SELECT `type` FROM `$drizzo_posts` WHERE `ID`='$drizzo_post_id'");
			if(!mysql_errno()) {
				$drizzo_page_type = @mysql_result($post_id_lookup, 0);
			}
			echo $drizzo_page_type;
			if(file_exists(drizzo_theme('local_dir') . $drizzo_page_type . ".php")) {
				$include_url = drizzo_theme('local_dir') . $drizzo_page_type . ".php";
			} else {
				$include_url = drizzo_theme('local_dir') . "index.php";
			}
		} elseif($drizzo_post_id && $_GET['id'] && !$drizzo_page_type) {
			$post_type_lookup = @mysql_query("SELECT `type` FROM `$drizzo_posts` WHERE `ID`='$_GET[id]'");
			if(!mysql_errno()) {
				$drizzo_page_type = @mysql_result($post_type_lookup, 0);
			}
			if(file_exists(drizzo_theme('local_dir') . $drizzo_page_type . ".php")) {
				$include_url = drizzo_theme('local_dir') . $drizzo_page_type . ".php";
			} else {
				$include_url = drizzo_theme('local_dir') . "index.php";
			}
		} elseif(!$drizzo_page_type && !$drizzo_post_id) {
			$drizzo_page_type = 'index';
			$include_url = drizzo_theme('local_dir') . "index.php";
		} else {
			if(file_exists(drizzo_theme('local_dir') . $drizzo_page_type . ".php")) {
				$include_url = drizzo_theme('local_dir') . $drizzo_page_type . ".php";
			} else {
				$include_url = drizzo_theme('local_dir') . "index.php";
			}
		}
		include($include_url);
				
	} else {
		include('basic.php');
	}
	drizzo_cleanup();
?>
